home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / dev / mui / MCC_SpeedBar.lha / MCC_SpeedBar / Developer / C / Examples / demo5.c < prev    next >
C/C++ Source or Header  |  2002-06-13  |  8KB  |  208 lines

  1.  
  2. #include <proto/exec.h>
  3. #include <proto/dos.h>
  4. #include <proto/datatypes.h>
  5. #include <proto/muimaster.h>
  6. #include <clib/alib_protos.h>
  7. #include <mui/SpeedBar_mcc.h>
  8. #include <mui/SpeedBarCfg_mcc.h>
  9. #include <datatypes/pictureclass.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12.  
  13. /***********************************************************************/
  14.  
  15. long __stack = 8192;
  16. struct Library *DataTypesBase;
  17. struct Library *MUIMasterBase;
  18.  
  19. /***********************************************************************/
  20.  
  21. #ifndef MAKE_ID
  22. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  23. #endif
  24.  
  25. /***********************************************************************/
  26.  
  27. struct MUIS_SpeedBar_Button buttons[] =
  28. {
  29.     {0, "_Get", "Get the disc.", 0, NULL},
  30.     {1, "Sa_ve", "Save the disc.", 0, NULL},
  31.     {2, "_Stop", "Stop the connection.", 0, NULL},
  32.     {MUIV_SpeedBar_Spacer},
  33.     {3, "_Disc", "Disc page.", 0, NULL},
  34.     {4, "_Matches", "Matches page.", 0, NULL},
  35.     {5, "_Edit", "Edit page.", 0, NULL},
  36.     {MUIV_SpeedBar_End},
  37. };
  38.  
  39. STRPTR pics[] =
  40. {
  41.     "PROGDIR:Pics/Get",
  42.     "PROGDIR:Pics/Save",
  43.     "PROGDIR:Pics/Stop",
  44.     "PROGDIR:Pics/Disc",
  45.     "PROGDIR:Pics/Matches",
  46.     "PROGDIR:Pics/Edit",
  47.     NULL
  48. };
  49.  
  50. /***********************************************************************/
  51.  
  52. static Object *
  53. loadDTBrush(struct MyBrush *brush,STRPTR file)
  54. {
  55.     struct BitMapHeader *bmh;
  56.     register Object     *dto;
  57.  
  58.     if (!(dto = NewDTObject(file,DTA_GroupID,GID_PICTURE,PDTA_Remap,FALSE,PDTA_DestMode,PMODE_V42,TAG_DONE)) ||
  59.         !(DoMethod(dto,DTM_PROCLAYOUT,NULL,1)) ||
  60.         !(GetDTAttrs(dto,PDTA_DestBitMap,&brush->BitMap,PDTA_CRegs,&brush->Colors,PDTA_BitMapHeader,&bmh,TAG_DONE)==3))
  61.     {
  62.         if (dto)
  63.         {
  64.             DisposeDTObject(dto);
  65.             dto = NULL;
  66.         }
  67.     }
  68.     else
  69.     {
  70.         brush->Width  = bmh->bmh_Width;
  71.         brush->Height = bmh->bmh_Height;
  72.     }
  73.  
  74.     return dto;
  75. }
  76.  
  77. /***********************************************************************/
  78.  
  79. #define TEMPLATE "STRIP,NUMBUTTON/N"
  80.  
  81. int
  82. main(int argc,char **argv)
  83. {
  84.     int res;
  85.  
  86.     if (DataTypesBase = OpenLibrary("datatypes.library",37))
  87.     {
  88.         if (MUIMasterBase = OpenLibrary("muimaster.library",19))
  89.         {
  90.             struct MyBrush                  brushes[sizeof(pics)/sizeof(STRPTR)-1], *b[sizeof(pics)/sizeof(STRPTR)-1];
  91.             struct MUIS_SpeedBarCfg_Config  c = {MUIV_SpeedBar_ViewMode_TextGfx, MUIV_SpeedBarCfg_Borderless|MUIV_SpeedBarCfg_Sunny};
  92.             Object                          *dtos[sizeof(pics)/sizeof(STRPTR)-1], *app, *win, *sb;
  93.             Object                          *cfg, *update;
  94.             int                             i;
  95.  
  96.             for (i = 0; pics[i]; i++)
  97.             {
  98.                 if (!(dtos[i] = loadDTBrush(brushes+i,pics[i])))
  99.                 {
  100.                     b[i] = NULL;
  101.                     printf("%s: warning can't load %s\n",argv[0],pics[i]);
  102.                 }
  103.                 else b[i] = brushes+i;
  104.             }
  105.  
  106.             if (app = ApplicationObject,
  107.                     MUIA_Application_Title,         "SpeedBar Demo5",
  108.                     MUIA_Application_Version,       "$VER: SpeedBarDemo5 14.4 (13.6.2002)",
  109.                     MUIA_Application_Copyright,     "Copyright 1999-2002 by Alfonso Ranieri",
  110.                     MUIA_Application_Author,        "Alfonso Ranieri <alforan@tin.it>",
  111.                     MUIA_Application_Description,   "Speed(Bar|Button|BarCfg).mcc test",
  112.                     MUIA_Application_Base,          "SPEEDBARTEST",
  113.                     SubWindow, win = WindowObject,
  114.                         MUIA_Window_ID,             MAKE_ID('M','A','I','N'),
  115.                         MUIA_Window_Title,          "SpeedBar Demo5",
  116.                         WindowContents, VGroup,
  117.                             Child, HGroup,
  118.                                 GroupFrame,
  119.                                 Child, sb = SpeedBarObject,
  120.                                     MUIA_Group_Horiz,               TRUE,
  121.                                     MUIA_SpeedBar_Borderless,       TRUE,
  122.                                     MUIA_SpeedBar_Sunny,            TRUE,
  123.                                     MUIA_SpeedBar_Buttons,          buttons,
  124.                                     MUIA_SpeedBar_StripUnderscore,  TRUE,
  125.                                     MUIA_SpeedBar_EnableUnderscore, TRUE,
  126.                                     MUIA_SpeedBar_BarSpacer,        TRUE,
  127.                                     MUIA_SpeedBar_Images,           b,
  128.                                 End,
  129.                                 Child, HSpace(0),
  130.                             End,
  131.                             Child, VSpace(0),
  132.                             Child, VGroup,
  133.                                 GroupFrameT("Appareance"),
  134.                                 Child, cfg = SpeedBarCfgObject,
  135.                                     MUIA_SpeedBarCfg_Config, &c,
  136.                                 End,
  137.                                 Child, VSpace(0),
  138.                                 Child, update = MUI_MakeObject(MUIO_Button,"_Update"),
  139.                             End,
  140.                             Child, VSpace(0),
  141.                         End,
  142.                     End,
  143.                 End)
  144.             {
  145.                 ULONG sigs = 0, id;
  146.  
  147.                 DoMethod(win,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,MUIV_Notify_Application,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  148.                 DoMethod(update,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,TAG_USER);
  149.  
  150.                 set(win,MUIA_Window_Open,TRUE);
  151.  
  152.                 while ((id = DoMethod(app,MUIM_Application_NewInput,&sigs))!=MUIV_Application_ReturnID_Quit)
  153.                 {
  154.                     if (id==TAG_USER)
  155.                     {
  156.                         struct MUIS_SpeedBarCfg_Config *c;
  157.  
  158.                         get(cfg,MUIA_SpeedBarCfg_Config,&c);
  159.  
  160.                         SetAttrs(sb,MUIA_SpeedBar_ViewMode,c->ViewMode,
  161.                                     MUIA_SpeedBar_Borderless,c->Flags & MUIV_SpeedBarCfg_Borderless,
  162.                                     MUIA_SpeedBar_RaisingFrame,c->Flags & MUIV_SpeedBarCfg_Raising,
  163.                                     MUIA_SpeedBar_SmallImages,c->Flags & MUIV_SpeedBarCfg_SmallButtons,
  164.                                     MUIA_SpeedBar_Sunny,c->Flags & MUIV_SpeedBarCfg_Sunny,
  165.                                     TAG_DONE);
  166.                     }
  167.  
  168.                     if (sigs)
  169.                     {
  170.                         sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  171.                         if (sigs & SIGBREAKF_CTRL_C) break;
  172.                     }
  173.                 }
  174.  
  175.                 MUI_DisposeObject(app);
  176.  
  177.                 res = RETURN_OK;
  178.             }
  179.             else
  180.             {
  181.                 printf("%s: can't create application\n",argv[0]);
  182.                 res = RETURN_FAIL;
  183.             }
  184.  
  185.             for (i = 0; pics[i]; i++)
  186.                 if (dtos[i]) DisposeDTObject(dtos[i]);
  187.  
  188.             CloseLibrary(MUIMasterBase);
  189.         }
  190.         else
  191.         {
  192.             printf("%s: Can't open muimaster.library ver 19 or higher\n",argv[0]);
  193.             res = RETURN_ERROR;
  194.         }
  195.  
  196.         CloseLibrary(DataTypesBase);
  197.     }
  198.     else
  199.     {
  200.         printf("%s: can't open dtatypes.library ver 37 or higher\n",argv[0]);
  201.         res = RETURN_ERROR;
  202.     }
  203.  
  204.     return res;
  205. }
  206.  
  207. /***********************************************************************/
  208.